package com.panda.takeaway.service.impl;

import com.panda.takeaway.auth.util.SecurityUtil;
import com.panda.takeaway.dao.SchoolMapper;
import com.panda.takeaway.dao.ShopMapper;
import com.panda.takeaway.dao.ShopSchoolMapper;
import com.panda.takeaway.entity.dto.CommonResult;
import com.panda.takeaway.entity.po.Shop;
import com.panda.takeaway.entity.po.ShopSchool;
import com.panda.takeaway.service.ShopSchoolService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author John
 * @create 2021-08-17-11:19
 */
@Service
public class ShopSchoolServiceImpl implements ShopSchoolService {

    @Resource
    private ShopSchoolMapper shopSchoolMapper;

    @Resource
    private ShopMapper shopMapper;

    @Resource
    private SchoolMapper schoolMapper;

    public CommonResult<?> addShopSchool(ShopSchool shopSchool) {

        Assert.notNull(shopSchool, "shopSchool对象为null");


        if (shopMapper.selectById(shopSchool.getShopId()) == null) {
            return CommonResult.operateFailWithMessage("该店铺不存在");
        }
        if (schoolMapper.selectById(shopSchool.getSchoolId()) == null) {
            return CommonResult.operateFailWithMessage("该学校不存在");
        }


        if (shopSchoolMapper.insert(shopSchool) > 0) {
            return CommonResult.operateSuccess();
        }

        return CommonResult.operateFailWithMessage("系统繁忙，请稍后重试！");

    }
}
